<template>
  <div class="progress-wrap" @touchstart.stop>
    <ul class="bg">
      <li v-for="(l,i) in list" :key="i" :class="['item', {'active-item':i===index-1, 'hidden-item': l.anchorPoint!==1}]" @touchstart="clickItemHandle(l,i)">
        <div v-if="l.anchorPoint===1" class="anchor">
          <span>{{ l.anchorPointName }}</span>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: 'Progress',
  props: {
    list: {
      type: Array,
      default: () => []
    },
    index: {
      type: Number,
      default: undefined
    }
  },
  data() {
    return {
    }
  },
  methods: {
    clickItemHandle(item, i) {
      this.$emit('update:index', i + 1)
      this.$emit('click', item, i + 1)
    }
  }
}
</script>
<style lang="less" scoped>
.progress-wrap{
  .bg{
    background-color: #fff;
    @height:2px;
    height: @height;
    border-radius: @height/2;
    margin: 0;
    padding: 0 45px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    .item{
      position: relative;
      @itemHeight: 6px;
      height: @itemHeight;
      width: @itemHeight;
      border-radius: 50%;
      background-color: #fff;
      cursor: pointer;
      .anchor{
        display: inline-block;
        position: absolute;
        top: -28px;
        transform: translateX(-50%);
        width: max-content;
        padding: 3px;
        background-color: rgba(30, 30, 30, 0.78);
        border-radius: 2px;
        color: #fff;
        font-size: 12px;
        &::after{
          content:'';
          display: block;
          width: 0px;
          height: 0px;
          border-top: 4px solid rgba(30, 30, 30, 0.78);
          border-right: 4px solid transparent;
          border-left: 4px solid transparent;
          border-bottom: 4px solid transparent;
          position: absolute;
          bottom: -8px;
          left: 50%;
          transform: translateX(-0.5px);
        }
      }
    }
    .hidden-item{
      width: 0;
      height: 0;
    }
    .active-item{
      border: 2px solid #fff;
      background-color: #16BC83;
    }
  }
}
</style>
